//package com.lt.test.consumer.controller;
//
//import com.alibaba.dubbo.config.annotation.Reference;
//import com.lt.test.api.RedisService;
//import com.lt.test.api.ShopService;
//import com.lt.test.api.ShopService2;
//import com.lt.test.common.constant.HttpRequestConstant;
//import com.lt.test.common.exception.CustomException;
//import com.lt.test.common.util.ExcelUtil;
//import com.lt.test.entity.DO.ShopDO;
//import com.lt.test.entity.DTO.ActiveUser;
//import com.lt.test.entity.DTO.PageDTO;
//import com.lt.test.entity.DTO.ResponseDTO;
//import com.lt.test.entity.QueryModel.MapQueryModel;
//import com.lt.test.consumer.util.WebUtils;
////import com.combinedpay.clouderp.sys.api.UserService;
//import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.authz.annotation.RequiresPermissions;
//import org.apache.shiro.subject.Subject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.OutputStream;
//import java.util.*;
//
//
///**
// * 云超市相关
// * @author zhengchuan
// *
// */
//@Controller
//@RequestMapping("/sys/clouderp")
//public class ClouderpController {
//	private static final Logger logger = LoggerFactory.getLogger(ClouderpController.class);
//
//	@Reference(version = "1.0.0")
//	private RedisService redisService;
////	@Reference(version = "1.0.0")
////	private UserService clouderpUserService;
//	@Reference(version = "1.0.0")
//	private ShopService shopService;
//	@Reference(version = "1.0.0")
//	private ShopService2 shopService2;
//
//	public ClouderpController() {
//	}
//
//	/**
//	 * 清理redis缓存
//	 * @param request
//	 * @param response
//	 * @param pattom
//	 * @return
//	 */
//	@RequestMapping(value = "/cleanCache")
//	public @ResponseBody
//    ResponseDTO register(HttpServletRequest request, HttpServletResponse response) {
//		ResponseDTO responseDTO = new ResponseDTO();
//		Map<String, String> result = com.lt.test.common.util.WebUtils.getAllParamMap(request);
//		String pattom = result.get("pattom") == null ? "" : result.get("pattom").toString();
//		String pattern = "*"+pattom+"*";
//		Set<byte[]> set = redisService.keys(pattern);
//		if(set==null){
//			responseDTO.setMessage("服务器错误");
//		}else if(set.isEmpty()) {
//			responseDTO.setMessage("没有找到匹配的缓存记录");
//		}else {
//			int size = set.size();
//			boolean isSuccess = redisService.remove(set);
//			if (isSuccess) {
//				logger.info("redis缓存清理成功,缓存匹配模式："+pattom+"，缓存大小："+size);
//				responseDTO.setSuccess(true);
//				responseDTO.setMessage("清理成功，本次共清理："+size+"条匹配缓存");
//			}
//		}
//		return responseDTO;
//	}
//	/**
//	 * 修改用户角色
//	 * @param request
//	 * @param response
//	 * @param phone 用户手机号
//	 * @param role 要修改成的角色
//	 * @throws IOException
//	 */
//	@RequestMapping("/changeRole")
//	public @ResponseBody
//    ResponseDTO changRole(HttpServletRequest request, HttpServletResponse response, String phone, String role) throws IOException{
//		ResponseDTO responseDTO = new ResponseDTO();
////		Map user = clouderpUserService.queryUserByMobile(phone);
////		if(user == null){
////			responseDTO.setMessage("用户不存在");
////		}else{
////			String userId = user.get("userId").toString();
////			Map<String,Object>  parameter = new HashMap<>();
////			parameter.put("userId", userId);
////			parameter.put("userType", role);
////			try {
////				clouderpUserService.updateUserType(parameter);
////				responseDTO.setMessage("修改成功");
////				responseDTO.setSuccess(true);
////			} catch (Exception e) {
////				responseDTO.setMessage("修改失败");
////				e.printStackTrace();
////			}
////		}
//		logger.info("-->修改用户角色:  result="+responseDTO);
//		return responseDTO;
//	}
//	@RequiresPermissions("CLOUDERPSHOP:VIEW")
//	@RequestMapping("/getShopInfo")
//	public @ResponseBody
//    PageDTO<ShopDO>  getShopInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
//		Map<String, String> params = new HashMap<>();
//		WebUtils.managerStringMap(params);
//		Integer page = Integer.valueOf(request.getParameter("page"));
//		Integer pageSize = Integer.valueOf(request.getParameter("rows"));
//		String sortedKey = request.getParameter("sidx");
//		String sortedValue = request.getParameter("sord");
//		String filters = request.getParameter("filters");
//		PageDTO<ShopDO> result = null;
//		try {
//			result = shopService.findShopByPage(page,pageSize,sortedKey,sortedValue,filters,params);
//		} catch (CustomException e) {
//			logger.error("获取店铺信息失败");
//			e.printStackTrace();
//			result =  new PageDTO<>();
//		}
//		return result;
//	}
//	@RequestMapping("/editShopInfo")
//	public @ResponseBody
//    ResponseDTO editShopInfo(HttpServletRequest request, HttpServletResponse response, ShopDO shop) {
//		ResponseDTO responseDTO = new ResponseDTO();
//		String oper = request.getParameter("oper");
//			try {
//				//UserDO userDO = (UserDO) request.getSession().getAttribute(SessionConstant.SESSION_USER_INFO);
//				/*if(userDO ==null) {
//					throw new CustomException("登陆超时，请重新登陆");
//				}*/
//				//主体
//				Subject subject = SecurityUtils.getSubject();
//				//身份
//				ActiveUser activeUser = (ActiveUser) subject.getPrincipal();
//				shop.setCreateTime(activeUser.getUsername());
//				shopService.editShopInfo(shop, oper);
//				responseDTO.setSuccess(true);
//				responseDTO.setCode(HttpRequestConstant.REQUEST_SUCCESS_CODE);
//				responseDTO.setMessage("操作成功");
//			} catch (CustomException e) {
//				responseDTO.setCode(HttpRequestConstant.SERVER_ERROR_CODE);
//				responseDTO.setMessage(e.getMessage());
//				e.printStackTrace();
//			} catch (Exception e) {
//				responseDTO.setCode(HttpRequestConstant.SERVER_ERROR_CODE);
//				responseDTO.setMessage("未知错误");
//				e.printStackTrace();
//			}
//		return responseDTO;
//
//	}
//
//	/**
//	 * 导出到excel -- 新的方法
//	 *
//	 * @param response
//	 * @throws Exception
//	 */
//	@RequestMapping("/clouderpExportExcel")
//	public void exportExcel_new(HttpServletRequest request, HttpServletResponse response,MapQueryModel params) throws Exception {
//		logger.info("开始生成excel表格");
//
//		WebUtils.managerStringMap(params.getStringMap());
//
//		List<Map<String, Object>> dataList = new ArrayList<>();
//
//
//		Map<String, Object> map = new HashMap<>();
//		String[] Keys = new String[0];
//		String[] columnNames = new String[0];
//		String fileName = "";
//		switch (request.getParameter("tableType")) {
//			case "shop":
//				dataList = shopService.findShopToExportExcel(params); //TODO 下次发布的时候记得修改这里的参数
//				map.put("sheetName", "云超市店铺信息");
//				Keys = new String[]{"SHOP_NAME", "ADDRESS", "USER_NAME", "MOBILE", "IS_EXP", "SHIPMENT_COUNT","SHIPMENTDAYCOUNT"};
//				columnNames = new String[]{"店铺名称", "地址", "创建人", "电话号码", "是否试点", "扫码次数","扫码天数"};
//				fileName = "云超市店铺信息";
//				break;
//			case "product":
//				map.put("sheetName", "库存分析-商品纬度");
//				Keys = new String[]{"CUST_NAME", "LAST_INVENTORY", "PERIOD_ORDER_QUANTITY", "PERIOD_SCAN_QUANTITY", "CURRENT_INVENTORY"};//,"STOCK_TO_SALES"
//				columnNames = new String[]{"商品名称", "上期库存", "期间订货量", "期间扫码销售量", "本期库存"};//,"存销比"
//				fileName = "库存分析-商品纬度";
//				break;
//			default:
//				break;
//		}
//		logger.info("添加sheetName的Map");
//		dataList.add(0, map);
//		logger.info("开始执行ExcelUtil.createHSSFWorkbook方法");
//		HSSFWorkbook wb = ExcelUtil.createHSSFWorkbook2(dataList, Keys, columnNames);
//		logger.info("执行ExcelUtil.createHSSFWorkbook方法完毕");
//		OutputStream out = response.getOutputStream();
//		response.reset();
//		response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
//		response.setContentType("application/msexcel;charset=UTF-8");
//		logger.info("设置响应信息完成");
//		//输出excel文件
//		wb.write(out);
//		out.close();
//		logger.info("结束生成excel表格");
//	}
//
//	/**
//	 * 收单行维护
//	 * @return
//	 * @throws IOException
//	 */
//	@RequestMapping("/bankMaintain")
//	public @ResponseBody
//    ResponseDTO bankMaintain(MapQueryModel params) throws Exception{
//		ResponseDTO responseDTO = new ResponseDTO();
//		String resultMessage = shopService2.bankMaintain(params.getStringMap());
//		responseDTO.setMessage(resultMessage);
//		responseDTO.setSuccess(true);
//		logger.info("-->收单行维护:  result="+responseDTO);
//		return responseDTO;
//	}
//}
